const app = getApp()
var stylecss = require('../../utils/stylecss.js');
Component({
  properties: {
    scrollTop: {
      type: Number,
      observer: function(newVal, oldVal) {
        this.updatscroll()
      }
    },
    styleType: {
      type: String
    },
    item: {
      type: Object,
      observer: function(newVal, oldVal) {
        this.updateRate()
      }
    }
  },
  data:{
    end:true,
    end_show:true
  },
    lifetimes: {
      ready: function() {
        let that = this;
        const query = wx.createSelectorQuery().in(this)
        setTimeout(() => { 
           query.select('#'+this.data.item.id).boundingClientRect(res=>{
                that.setData({
                  top:res.top
                })
              }).exec();
         }, 0);
       },
      attached: function () {
       
     }
    },
    methods: {
      updatscroll:function(){
        var nowtop=this.data.scrollTop-this.data.top
        var oldanima=this.data.oldanima
        if(nowtop<=0){
         this.setData({
           anima:oldanima
         })
        }else{
          this.setData({
              anima:''
          })
        }
     },
      toyuyue:function(e){ 
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=good_detail&activity=service&goods_id='+e.currentTarget.dataset.id,
        })
      },
      updateRate:function(){
        var item=this.data.item
        var type=item.type
        if(item.type=='services1'||item.type=='services2'){
          type='services'
        }
        var list=this.data.item.list;
        var css=stylecss.css(this.data.item.id);
        var anima=stylecss.animated(this.data.item.id);
        this.setData({
          oldanima:anima,
          anima:anima,
          css:css
        })
        var item_image=this.data.item.id+' .item_image';
        var group_title=this.data.item.id+' .group_title';
        var group_item=this.data.item.id+' .group_item';
        var item_image_css=stylecss.css(item_image);
        var group_title_css=stylecss.css(group_title);
        var group_item_css=stylecss.css(group_item);
        this.setData({
          globalColor:app.globalData.globalColor,
          item_image_css:item_image_css,
          group_title_css:group_title_css,
          group_item_css:group_item_css
        })
        var that=this
        wx.request({
          url: app.globalData.siteroot,
           data: {
             do:'List_Data',
             num:that.data.item.num, 
             class_ids:that.data.item.class_ids,
             sort:that.data.item.sort,
             order:that.data.item.order,
             ids:'',
             data_type:'auto',
             page:that.data.item.page,
             type:type,
             user_id:wx.getStorageSync('user_id')
          },
         success: function(res) {
           that.setData({
             list:res.data.info
           })
         }
        })
      }
          
    }
});
